package tacos.web.api;

import java.util.Date;

import lombok.Getter;
import org.springframework.hateoas.CollectionModel;
import org.springframework.hateoas.RepresentationModel;
import org.springframework.hateoas.server.core.Relation;
import org.springframework.http.HttpStatus;
import tacos.Taco;

/**
 * simon:为Taco对象添加上Link
 */
//@Relation(value = "tacos", collectionRelation = "tacos")
public class TacoResource extends RepresentationModel<TacoResource> {

  //IngredientResourceAssembler的作用是为Taco中Ingredients集合中的每一个Ingredient添加上Link
  private static final IngredientResourceAssembler
          ingredientAssembler = new IngredientResourceAssembler(IngredientController.class, IngredientResource.class);

  @Getter
  private String name;

  @Getter
  private Date createdAt;

  @Getter
  private CollectionModel<IngredientResource> ingredients;

  public TacoResource(Taco taco) {
    this.name = taco.getName();
    this.createdAt = taco.getCreatedAt();
    this.ingredients = ingredientAssembler.toCollectionModel(taco.getIngredients());

  }
}